<%@ include file="/WEB-INF/jsp/includes/include.jsp" %>
<%@ taglib prefix="bids" tagdir="/WEB-INF/tags/bids" %>
<%@ taglib prefix="feedbacks" tagdir="/WEB-INF/tags/feedbacks" %>
<%@ include file="/WEB-INF/jsp/includes/header.jsp" %>

<h2>${posting.title}</h2>
<div style="float:right; margin-left:10px;">
	<p>Auction start date: <strong><fmt:formatDate type="both" dateStyle="medium" timeStyle="medium" value="${posting.startDate}" /></strong></p>
	<div id="end_date" style="display:none"><fmt:formatDate type="both" dateStyle="medium" timeStyle="medium" value="${posting.endDate}" /></div>
	<p>Time left to the end of the auction:</p>
	<div id="defaultCountdown"></div>
	<p>Auction end date: <strong><fmt:formatDate type="both" dateStyle="medium" timeStyle="medium" value="${posting.endDate}" /></strong></p>
</div>
<p><c:out value="${posting.description}" escapeXml="true" /></p>
<p>Reserve price: <strong>(US $${posting.price})</strong></p>
<!-- list bids -->
<c:if test="${not empty param.bidplacedaftertime && posting.status == 2}">
<p class="error">We are sorry, we could not accept that bid - it occurred after the auction's end time has past.</p>
</c:if>
<c:if test="${posting.status eq 2}">
<p class="error">This auction is CLOSED.</p>
</c:if>
<p>
	<strong>Placed bids</strong>:
	<c:if test="${currentUser.id == posting.user.id}"><span class="error"><br />(It's your posting, you can't bid on your own auction! :))</span></c:if>
</p>
<bids:list bids="${posting.bids}" />
<!-- 
	render bids:add only if posting status is set to pending 
	and current user is not the owner of the posting
-->
<c:if test="${posting.status == 1 && currentUser.id != posting.user.id}">
	<sec:authorize ifAnyGranted="ROLE_BUYER,ROLE_SELLER,ROLE_ADMIN">
		<bids:add />
	</sec:authorize>
	<sec:authorize ifNotGranted="ROLE_BUYER,ROLE_SELLER,ROLE_ADMIN">
		<p><a href="<c:url value="/login.jsp"/>">You must be login to place a bid.</a></p>
	</sec:authorize>
</c:if>


<!-- render feedback for posting's seller -->
<feedbacks:list feedbacks="${posting.user.feedbacks}" />

<sec:authorize ifAnyGranted="ROLE_BUYER">
	<!-- show feedback-add only if winner id equals currently logged in user 
	 	 and no feedback is posted yet 
	-->
	<c:if test="${posting.winner.id == currentUser.id && posting.feedback == null}">
			<feedbacks:add />
	</c:if>
</sec:authorize>

<p style="clear:both"><a href="<c:url value="/postings/"/>">Return to all postings</a></p>
<%@ include file="/WEB-INF/jsp/includes/footer.jsp" %>